from Controller.EventDefine import event_GAMECONTROL_INITIALIZEDONE
from Cube.map.QMapMgr.EventDefine import event_MAPMGRFSM_INTERMEZZO
from Cube.game import QObjectPool, CmdSendGet, ObjectPoolGet
from QMapBodyHandler import QMapBodyHandler
from Cube.utility.RandomSeed import RandomSeedAssign


class QMapBody(QMapBodyHandler):
    def __init__(self, mapHeader):
        self.MapInfo = mapHeader.MapInfo
        self.MemberList = mapHeader.MemberList
        RandomSeedAssign(mapHeader.RandomSeedGet())

        self.ObjectPool = ObjectPoolGet()
        self.CmdSend = CmdSendGet()

        QMapBodyHandler.__init__(self)

    # override it
    def Initialize(self):
        # system object loading
        pass

    def InitializeDone(self):
        messenger.send(event_GAMECONTROL_INITIALIZEDONE)

    def ID2Obj(self, objID):
        ret = self.ObjectPool.ObjectGet(objID)
        return ret

    def ExitMap(self):
        messenger.send(event_MAPMGRFSM_INTERMEZZO)

    def run(self):
        self.LogicUpdateOn()

    def pause(self):
        self.LogicUpdateOff()

    def destroy(self):
        # called by MapBodyController
        # destroy local objects
        self.ObjectPool.destroy(flag = LOCALOBJECTFLAG)
        self.ObjectPool.IDRecycle()
